import 'package:flutter/material.dart';
void main() {
  runApp(
     MaterialApp(
      home: Material(child: ShakeAnimation()),
    ),
  );
}


class ShakeAnimation extends StatefulWidget {
  @override
  _ShakeAnimationState createState() => _ShakeAnimationState();
}

class _ShakeAnimationState extends State<ShakeAnimation> with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  late Animation<double> _animation;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(seconds: 2),
      vsync: this,
    );
    _animation = Tween(begin: 0.0, end: 200.0).animate(_controller);
    _controller.forward();

    // WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
    //   _controller.forward();
    // });
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Center(
        child: AnimatedBuilder(
          animation: _animation,
          builder: (context, child) {
            return Container(
              margin: EdgeInsets.only(left: _animation.value),
              child: Text('抖动动画'),
            );
          },
        ),
      ),
    );
  }
}